import module namespace page="http://sendmeafilter.com/common/page" at "../common/page.xqy";

declare boundary-space preserve;
declare option xdmp:mapping "false";

declare variable $affiliateId := xdmp:get-request-field('id');
declare variable $affiliate := /affiliate[@affiliateid = $affiliateId];

page:page (
	(
		page:meta('title', 'Back Office - SendMeAFilter.com'),
		page:meta('backoffice')
	),

	<div class="wrapper">
		<div class="caption">	
			<div float="right">
				{if($affiliate) then
				<h3>Edit : {$affiliate/name/text()}</h3>
				else
				<h3>Add Affiliate</h3>
				}
			</div>
			<br/>
			<div>
				 <div>
	            	<form name="theForm" method="post" onSubmit="return validateForm(this);" action="/backoffice/editaffiliatepost" enctype="multipart/form-data">
						<table class="affiliate-table" width="100%">
							<colgroup span="1" width="20%"></colgroup>
							<colgroup width="80%" align="justify"></colgroup>
							<tr>
								<th class="table-align-right">Name:</th> 
								<th class="table-align-left"><input type="text" style="width:200px" name="name" value="{$affiliate/name}"/></th>
							</tr>
							<tr>
								<th class="table-align-right">Username:</th> 
								<th class="table-align-left"><input type="text" style="width:200px" name="username" value="{$affiliate/username}"/></th>
							</tr>
							<tr>
								<th class="table-align-right">Email:</th>
								<th class="table-align-left"><input type="text" style="width:200px" name="email" value="{$affiliate/email}"/></th>
							</tr>
							<tr>
								<th class="table-align-right">Address:</th> 
								<th class="table-align-left"><input type="text" name="address1" style="width:200px" value="{$affiliate/address/line[1]}"/></th>
							</tr>
							<tr>
								<th class="table-align-right"></th>
								<th class="table-align-left"><input type="text" name="address2" style="width:200px" value="{$affiliate/address/line[2]}"/></th>
							</tr>
							<tr>
								<th class="table-align-right">City:</th>
								<th class="table-align-left"><input type="text" name="city" value="{$affiliate/address/city}"/></th>
							</tr>
							<tr>
								<th class="table-align-right">State:</th>
								<th class="table-align-left"><select class="facets" name="state" id="select" size="1">
									<option value="UT">{if ($affiliate/address/state="UT")then attribute selected{"selected"}else()}
										<span>Utah</span>
									</option>
									<option value="ID">{if ($affiliate/address/state="ID")then attribute selected{"selected"}else()}
										<span class="all">Idaho</span>
									</option>
									<option value="CO">{if ($affiliate/address/state="CO")then attribute selected{"selected"}else()}
										<span class="all">Colorado</span>
									</option>
								</select></th>
							</tr>
							<tr>
								<th class="table-align-right">Zip:</th>
								<th class="table-align-left"><input type="text" name="zip" style="width:80px" value="{$affiliate/address/zip}"/></th>
							</tr>
							<tr>
								<th class="table-align-right">Phone:</th>
								<th class="table-align-left"><input type="text" name="phone" style="width:100px" value="{$affiliate/phone}"/></th>
							</tr>
							<tr>
								<th class="table-align-right">Active:</th>
								<th class="table-align-left"><input type="checkbox" name="active" checked="checked"/></th>
							</tr>
							
						</table>
						
						<br/>
						<input type="hidden" name="id" value="{$affiliateId}"/>
						<input id="inputButton" type="submit" name="submit" value="Save"/>  
						&nbsp;
						&nbsp;
						<input id="inputButton" type="submit" value="Cancel" onclick="history.back()"/>
						&nbsp;
						&nbsp;
						<input id="inputButton" type="submit" name="submit" value="Remove" onclick="return confirm('Are you sure you want to delete this affiliate?');" />
						<input name="file" type="hidden" value="{xdmp:get-request-field('file')}"/>
					</form>
				</div>              
			</div>
		</div>
	</div>	
)